package repertory.android.ericchen.androidrepertory.activity;

import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.util.ArrayList;

import repertory.android.ericchen.androidrepertory.R;
import repertory.android.ericchen.androidrepertory.mvp.login.LoginActivity;
import repertory.android.ericchen.androidrepertory.util.D2NavigationUtils;
import repertory.android.ericchen.androidrepertory.view.BottomPopupDialog;
import repertory.android.ericchen.androidrepertory.view.CommonDialog;
import repertory.android.ericchen.androidrepertory.view.MyBottomPoupDialog;

public class MainActivity extends FragmentActivity {

    private Button BtnDatabase;
    private Button BtnDialog;
    private Button BtnBottomDialog;
    private Button BtnUtils;
    private Button BtnViews;
    private Button BtnMVP;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        BtnDatabase = (Button)findViewById(R.id.btn_database);
        BtnDatabase.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                D2NavigationUtils.startForActivity(getApplicationContext(),DataBaseActivity.class);
            }
        });
        BtnDialog =(Button)findViewById(R.id.btn_dialog);
        BtnDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDialog();
            }
        });
        BtnBottomDialog =(Button)findViewById(R.id.btn_bottom_dialog);
        BtnBottomDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(bottomPopupDialog!=null){
                    bottomPopupDialog.dismiss();
                    bottomPopupDialog =null;
                }
                bottomPopupDialog = new MyBottomPoupDialog(MainActivity.this, null,menuItemClickListener,initData(),true,initIconData());
                bottomPopupDialog.getTitleView().setVisibility(View.GONE);
                bottomPopupDialog.hideOkBtn();
                bottomPopupDialog.showFromBottom();
            }
        });
        BtnUtils = (Button)findViewById(R.id.btn_utils);
        BtnUtils.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                D2NavigationUtils.startForActivity(getApplicationContext(),UtilsActivity.class);
            }
        });
        BtnViews =(Button)findViewById(R.id.btn_view);
        BtnViews.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                D2NavigationUtils.startForActivity(getApplicationContext(),ViewActivity.class);
            }
        });
        BtnMVP = (Button)findViewById(R.id.btn_mvp);
        BtnMVP.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                D2NavigationUtils.startForActivity(getApplicationContext(),LoginActivity.class);
            }
        });
    }
    private ArrayList<String> initData(){
        ArrayList<String> data = new ArrayList<>();
        data.add("拍摄照片");
        data.add("从手机相册选择");
        return data;
    }
    private ArrayList<Integer> initIconData(){
        ArrayList<Integer> data = new ArrayList<>();
        data.add(R.mipmap.ic_launcher);
        data.add(R.mipmap.ic_launcher);
        return data;
    }
    private MyBottomPoupDialog.OnMenuItemClickListener menuItemClickListener = new MyBottomPoupDialog.OnMenuItemClickListener() {
        @Override
        public void onItemClick(int position) {
            switch (position){
                case 0:
                    Toast.makeText(getApplicationContext(),"拍摄照片",Toast.LENGTH_SHORT).show();
                    break;
                case 1:
                    Toast.makeText(getApplicationContext(),"从手机相册选择",Toast.LENGTH_SHORT).show();
                    break;
            }
            //bottomPopupDialog.dismiss();
        }
    };
    private CommonDialog dialog;
    private MyBottomPoupDialog bottomPopupDialog;
    private void showDialog(){
        if(dialog!=null){
            dialog.dismiss();
        }
        dialog = new CommonDialog(MainActivity.this, "标题", "内容", "取消", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                closeDialog();
            }
        }, "确定", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getApplicationContext(),"确定",Toast.LENGTH_SHORT).show();
                closeDialog();
            }
        });
        dialog.show();
    }
    private void closeDialog(){
        if(dialog!=null){
            dialog.dismiss();
            dialog =null;
        }
    }


}
